<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>九宫格 抽奖转盘演示</title>
<link rel="stylesheet" href="rexue.css" />


</head>
<body>


	<div class="yuanbao">
				<div class="erji"><span style="color: #ffe65c;line-height: 50px;margin-left: 30px;">清凉礼包中赠送的绑定元宝数量为：<input type="text"  value="3"/>个</span></div>
				<div class="choujiang"><a style="color: white;line-height: 50px;margin-left: 30px;">抽奖次数：<input placeholder="3">次</a></div>
				<div class="ziliao">
					<div class="ziliao_1" onclick="document.getElementById('img').style.display=(document.getElementById('img').style.display=='none')?'':'none'"></div>
						<div id="img" style="width: 500px;height: 400px;display: none;position: absolute;margin-top: 60px;margin-left: -200px;background-color: #155dac;">
							<div class="jiangping"><h2>我的奖品</h2></div>
							<div style="background-image: url(img/关闭按钮.png);width: 93px;height: 93px;float: left;margin-left: 420px;margin-top: -80px;" onclick="document.getElementById('img').style.display='none'"></div>
							<div class="xingmin"><input type="text" name="names"></div>
							<div class="qq"><input type="text" name="names"></div>
							<div class="dianhua"><input type="text" name="names"></div>
							<div class="jiaose"><input type="text" name="names"></div>
							<div class="qufu">
								<input type="text" name="names"></div>
						</div>
					
					<div class="ziliao_2" onclick="document.getElementById('none').style.display=(document.getElementById('none').style.display=='none')?'':'none'" ></div>
						<div id="none" style="width: 400px;height: 350px;border: 0px solid;display: none;position: absolute;background-color: #00BFFF;margin-top: 60px;margin-left: 50px;">
							
							<div class="tianxie"><h3>填写资料</h3></div>
							<div style="background-image: url(img/关闭按钮.png);width: 93px;height: 93px;float: left;margin-left: 320px;margin-top: -80px;" onclick="document.getElementById('none').style.display='none'"></div>
							<div class="xingmin">姓名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="names"></div>
							<div class="qq">QQ&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="names"></div>
							<div class="dianhua">联系电话&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="names"></div>
							<div class="jiaose">游戏角色名&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="names"></div>
							<div class="qufu">游戏区服&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="names"></div>
							<div class="tijiao"><input type="button" onclick="document.getElementById('tan_1').style.display=(document.getElementById('tan_1').style.display=='none')?'':'none'" value="提交"/>
							    <div id="tan_1" style="width: 300px;height: 100px;background-color: #155DAC;display: none;margin-left: 50px;margin-top: -200px;position: absolute;">
							    	<p style="color: white;font-size: 15px;margin-top: 45px;margin-left: 20px;">恭喜你获得三次抽奖机会——谢谢参与</p>
							    	<div style="background-image: url(img/关闭按钮.png);width: 83px;height: 83px;margin-top: -110px;margin-left: 235px;" onclick="document.getElementById('tan_1').style.display='none'"></div>
							    </div>
							</div>
						</div>
					
				</div>
				
					
<div id="lottery">
	<table border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td class="lottery-unit lottery-unit-0"><img src="img/3.jpg"></td>
			<td class="lottery-unit lottery-unit-1"><img src="img/2.jpg"></td>
			<td class="lottery-unit lottery-unit-2"><img src="img/1.jpg"></td>
            <td class="lottery-unit lottery-unit-3"><img src="img/12.jpg"></td>
		</tr>
		<tr>
			<td class="lottery-unit lottery-unit-11"><img src="img/4.jpg"></td>
			<td colspan="2" rowspan="2"><a href="#"></a><img src="img/dianjichoujiang.png" onclick="start()"></td>
			<td class="lottery-unit lottery-unit-4"><img src="img/11.jpg"></td>
		</tr>
		<tr>
			<td class="lottery-unit lottery-unit-10"><img src="img/5.jpg"></td>
			<td class="lottery-unit lottery-unit-5"><img src="img/8.jpg"></td>
		</tr>
        <tr>
			<td class="lottery-unit lottery-unit-9"><img src="img/9.jpg"></td>
			<td class="lottery-unit lottery-unit-8"><img src="img/6.jpg"></td>
			<td class="lottery-unit lottery-unit-7"><img src="img/7.jpg"></td>
            <td class="lottery-unit lottery-unit-6"><img src="img/10.jpg"></td>
		</tr>
	</table>
</div>
				
	</div>


<script type="text/javascript" src="jquery-1.8.3.min.js"></script>

<script type="text/javascript">
var lottery={
	index:-1,	//当前转动到哪个位置，起点位置
	count:0,	//总共有多少个位置
	timer:0,	//setTimeout的ID，用clearTimeout清除
	speed:20,	//初始转动速度
	times:0,	//转动次数
	cycle:50,	//转动基本次数：即至少需要转动多少次再进入抽奖环节
	prize:-1,	//中奖位置
	init:function(id){
		if ($("#"+id).find(".lottery-unit").length>0) {
			$lottery = $("#"+id);
			$units = $lottery.find(".lottery-unit");
			this.obj = $lottery;
			this.count = $units.length;
			$lottery.find(".lottery-unit-"+this.index).addClass("active");
		};
	},
	roll:function(){
		var index = this.index;
		var count = this.count;
		var lottery = this.obj;
		$(lottery).find(".lottery-unit-"+index).removeClass("active");
		index += 1;
		if (index>count-1) {
			index = 0;
		};
		$(lottery).find(".lottery-unit-"+index).addClass("active");
		this.index=index;
		return false;
	},
	stop:function(index){
		this.prize=index;
		return false;
	}
};

function roll(){
	lottery.times += 1;
	lottery.roll();
	if (lottery.times > lottery.cycle+10 && lottery.prize==lottery.index) {
		clearTimeout(lottery.timer);
		lottery.prize=-1;
		lottery.times=0;
		click=false;
	}else{
		if (lottery.times<lottery.cycle) {
			lottery.speed -= 10;
		}else if(lottery.times==lottery.cycle) {
			var index = Math.random()*(lottery.count)|0;
			lottery.prize = index;		
		}else{
			if (lottery.times > lottery.cycle+10 && ((lottery.prize==0 && lottery.index==7) || lottery.prize==lottery.index+1)) {
				lottery.speed += 110;
			}else{
				lottery.speed += 20;
			}
		}
		if (lottery.speed<40) {
			lottery.speed=40;
		};
		//console.log(lottery.times+'^^^^^^'+lottery.speed+'^^^^^^^'+lottery.prize);
		lottery.timer = setTimeout(roll,lottery.speed);
	}
	return false;
}

var click=false;

window.onload=function(){
	lottery.init('lottery');
	$("#lottery a").click(function(){
		if (click) {
			return false;
		}else{
			lottery.speed=100;
			roll();
			click=true;
			return false;
		}
	});
};
function start(){lottery.start()};
</script>



</body>
</html>